package lagou.user.server.lagouuser.service.impl;


import lagou.user.server.lagouuser.dao.UserBaseDao;
import lagou.user.server.lagouuser.entity.UserBase;
import lagou.user.server.lagouuser.feign.EmailServiceFeignClient;
import lagou.user.server.lagouuser.service.UserBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserBaseServiceImpl implements UserBaseService {

    @Autowired
    private UserBaseDao userBaseDao;






    @Autowired
    private EmailServiceFeignClient emailServiceFeignClient;


    @Override
    public String verifyAndInsert(String email, String pwd,String verifyCode){
         String reusult = emailServiceFeignClient.verifyCode(email, verifyCode);
         if ("success".equals(reusult)){
             insertUserBase(email,pwd);
             return "success";
         } else {
             return "验证码已过期";
         }
    }

    @Override
    public int insertUserBase(String email, String pwd){
        UserBase userBase=new UserBase();
        userBase.setUserAccount(email);
        userBase.setUserPwd(pwd);
       return userBaseDao.insertUserBase(userBase);
    }


    @Override
    public UserBase findUserBase(String email,String pwd){
        UserBase userBase=new UserBase();
        userBase.setUserAccount(email);
        userBase.setUserPwd(pwd);
        return userBaseDao.findBase(userBase);
    }
}
